package org.xiaodongwei.jvm.op;

import org.xiaodongwei.jvm.exe.JVMStack;
import org.xiaodongwei.jvm.utils.StringUtils;
import tech.medivh.classpy.classfile.bytecode.Instruction;
import tech.medivh.classpy.classfile.bytecode.Ldc;
import tech.medivh.classpy.classfile.constant.ConstantPool;

public class LdcOpcodeExecute extends OpCodeExecute{

    public LdcOpcodeExecute(JVMStack jvmStack, ConstantPool constantPool) {
        this.jvmStack = jvmStack;
        this.constantPool = constantPool;
    }

    @Override
    public void execute(Instruction instruction) {
        // 从常量池中获取对应的常量
        Ldc ldc = (Ldc) instruction;
        String desc = ldc.getConstantInfo(constantPool).getDesc();
        Object v = StringUtils.detectType(desc).getValue();
        jvmStack.peek().getOperateStack().push(StringUtils.detectType(desc).getValue());
    }
}
